package com.rxnetwork.sample.module.home.fragment.test

import com.rxnetwork.sample.api.Api
import com.rxnetwork.sample.api.ApiInterface
import com.rxnetwork.sample.model.ListModel
import com.rxnetwork.sample.mvp.BasePresenterImpl
import com.rxnetwork.sample.utils.network.AppNetWorkListener
import com.rxnetwork.sample.utils.network.AppNetWorkManager

class TestFragmentPresenter : BasePresenterImpl<TestFragmentContract.MyView>(), TestFragmentContract.Presenter {

    override fun login(userName: String, password: String) {
        AppNetWorkManager
                .instance
                .setBaseUrl(Api.ZL_BASE_API)
                .getApi(AppNetWorkManager.observable(ApiInterface::class.java).getList("daily", 20, 0), object : AppNetWorkListener<List<ListModel>> {
                    override fun onNetWorkError(e: Throwable) {
                        mView!!.loginFailed("登入失败")
                    }

                    override fun onNetWorkSuccess(data: List<ListModel>) {
                        mView!!.loginSuccess("登入成功")
                    }
                })

        AppNetWorkManager
                .instance
                .setBaseUrl(Api.TEST_URL)
                .getApi(AppNetWorkManager.observable(ApiInterface::class.java).getTestString("lol", 1, 20), object : AppNetWorkListener<Any> {
                    override fun onNetWorkError(e: Throwable) {
                        mView!!.loginFailed("请求失败-------String")
                    }

                    override fun onNetWorkSuccess(data: Any) {
                        mView!!.loginSuccess("请求成功-------String")
                    }
                })
    }
}
